﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SF.Base.Core;

namespace SF.Dict.Web {
	public partial class Login : BasePage {
		protected void Page_Load(object sender, EventArgs e) {
			if (!Page.IsPostBack) {
				if (Request.GetStr("logout") == "I'll come back") {
					Session.Clear();
				}

				Global.DTUser = UserRules.GetUserByLogin("nitu2012@126.com");

				if(Global.DTUser != null){
					Response.Redirect(Server.UrlDecode(Request.GetStr("return", "/home.aspx")));
				}
			}
		}

		protected void btn_submit_Click(object sender, EventArgs e) {
			string Account = tb_account.Text.Trim();
			string Password = tb_password.Text.Trim();

			if (string.IsNullOrEmpty(Account)) {
				hf_error.Value = "E160201";
				return;
			}

			if (string.IsNullOrEmpty(Password)) {
				hf_error.Value = "E160202";
				return;
			}

			UserEntity User = UserRules.GetUserByLogin(Account);

			if (User == null) {
				hf_error.Value = "E160203";
				return;
			}

			if (Password != User.Pass) {
				hf_error.Value = "E160204";
				return;
			}

			Global.DTUser = User;

			Response.Redirect("/" + Request.GetStr("return", "home.aspx"));
		}
	}
}